/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.commands.diagram;

import com.cea.papyrus.core.utils.Debug;
import com.cea.papyrus.diagraminterchange2.di2.Diagram;

/**
 * 
 */
public class OpenDiagramCommand extends org.eclipse.gef.commands.Command {
	
	/**
	 * Debug channel.
	 */
	private static final int channel = 21;
	
	/**
	 * 
	 */
	protected Diagram diagram;

	/**
	 * 
	 * 
	 * @param diagram 
	 */
	public OpenDiagramCommand(Diagram diagram) {
		super("OpenDiagramCommnand");
		this.diagram = diagram;
	}

	/**
	 * 
	 */
	@Override
	public void execute() {
		Debug.debug(this, "execute open diagram on: "+diagram.getName()+"["+diagram.isIsVisible()+" - "+diagram.getType()+"]", channel);
		redo();
	}

	/**
	 * 
	 */
	@Override
	public void redo() {
		Debug.debug(this, "redo diagram on: "+diagram.getName()+"["+diagram.isIsVisible()+" - " +diagram.getType()+"]", channel);
		diagram.setIsVisible(true);
	}


	/**
	 * 
	 */
	@Override
	public void undo() {
		Debug.debug(this, "undo diagram on: "+diagram.getName()+"["+diagram.isIsVisible()+" - " +diagram.getType()+"]", channel);
		diagram.setIsVisible(false);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#canExecute()
	 */
	@Override
	public boolean canExecute() {
		// always true, so editors can be "re-opened" even if there were already opened.
        return true;
	}
}
